﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using TodoList.ViewModel;
using TodoList.Common;
using TodoList.Mode;
using TodoList.Converter;
using FirstFloor.ModernUI.Windows.Controls;
using System.Windows;

namespace TodoList.Command
{
    class DeleteCommand : ICommand
    {
        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {            
            MessageBoxResult res = ModernDialog.ShowMessage("Are you sure do you want to delete ?", "Todo Delete", System.Windows.MessageBoxButton.YesNo);            
            if (res == MessageBoxResult.Yes)
            {
                TodoDeleteBind todoMerget = parameter as TodoDeleteBind;
                TodoVM vm = todoMerget.TodoViewModel;
                string Id = todoMerget.Id as string;
                List<Todo> todoList = Utils.GetTodoList(vm.FileName);
                Todo toDelete = todoList.Where(to => to.Id.Equals(Id)).FirstOrDefault();
                todoList.Remove(toDelete);
                Utils.SaveTodoItem(vm.FileName, todoList);
                vm.TodoList = todoList;
                Console.WriteLine("Item Deleted");
            }
        }
        #endregion
    }
}
